package org.jeecg.modules.golf.plan.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.modules.golf.plan.entity.PlanTypeMapping;
import org.jeecg.modules.golf.plan.mapper.PlanTypeMappingMapper;
import org.jeecg.modules.golf.plan.service.IPlanTypeMappingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description: 方案分类方案关联
 * @Author: jeecg-boot
 * @Date:   2020-10-20
 * @Version: V1.0
 */
@Service
public class PlanTypeMappingServiceImpl extends ServiceImpl<PlanTypeMappingMapper, PlanTypeMapping> implements IPlanTypeMappingService {

	@Autowired
	private PlanTypeMappingMapper planTypeMappingMapper;

	@Override
	public List<PlanTypeMapping> selectByMainId(Long mainId) {
		return planTypeMappingMapper.selectByMainId(mainId);
	}

	@Override
	public List<PlanTypeMapping> selectByPlanIdList(List<Long> planIdList) {
		return planTypeMappingMapper.selectByPlanIdList(planIdList);
	}

	/**
	 * 批量保存planType
	 *
	 * @param planTypeMappings
	 */
	@Override
	public void savePlanTypeMapping(List<PlanTypeMapping> planTypeMappings,Long planId) {
		if(planTypeMappings!=null && planTypeMappings.size()>0) {
			if(planTypeMappings.size()>5){
				throw  new JeecgBootException("方案分类最多个关联5个");
			}
			for(PlanTypeMapping entity:planTypeMappings) {
				//外键设置
				entity.setPlanId(planId);
				planTypeMappingMapper.insert(entity);
			}
		}
	}


}
